package com.atung.parking.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Administrator
 */
public class DateConvertUtil {

    public static long convertToMillis(String dateStr) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(dateStr);
        return date.getTime();
    }

    public static Long convertQueryStartToMillis(String dateStr) {
        try {
            String fullDateStr = dateStr + " 00:00:00";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(fullDateStr);
            return date.getTime();
        } catch (ParseException e) {
            return null;
        }

    }

    public static Long convertQueryEndToMillis(String dateStr) {
        try {
            String fullDateStr = dateStr + " 23:59:59";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(fullDateStr);
            return date.getTime();
        } catch (ParseException e) {
            return null;
        }
    }

}
